package com.example.dc.Controller;

import com.example.dc.Service.SicknessService;
import com.example.dc.Service.UserService;
import com.example.dc.domain.Sickness;
import com.example.dc.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/sickness")
public class SicknessController {
    @Autowired
    private SicknessService sicknessService;

    @Autowired
    private UserService userService;

    @GetMapping("/all")
    public Result getSickness(){
        List<Sickness> sicknesses=sicknessService.getSickness();
        return Result.success(sicknesses);
    }

    @PostMapping("/add")
    public Result UpdateUserAndSickness(@RequestBody Map<String,Object> map){
        Integer userId=(Integer) map.get("userId");
        Integer age=(Integer)map.get("age");
        String name=(String) map.get("name");
        System.out.println("用户姓名："+name);
        Character sex=map.get("sex").toString().charAt(0);
        List<Integer> sicknessList=(List<Integer>) map.get("sickness");
        sicknessService.addSick(userId,sicknessList);
        userService.updateUserAuth(userId,name,age,sex);
        userService.updateUserInfo(name,null,null,userId);
        return Result.success();
    }
}
